package com.zang.blogz.utils;

import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.stp.StpUtil;
import io.github.vampireachao.stream.core.optional.Opp;


import static cn.dev33.satoken.exception.NotLoginException.DEFAULT_MESSAGE;
import static cn.dev33.satoken.exception.NotLoginException.NOT_TOKEN_MESSAGE;

/**
 * @Author: ZVerify
 * @Description: 用户信息
 * @DateTime: 2022/8/28 20:33
 **/

public class UserInfoUtil {

    public static Integer getLoginUserId(){
        Object loginIdDefaultNull = StpUtil.getLoginIdDefaultNull();

        loginIdDefaultNull = Opp.of(loginIdDefaultNull).orElseThrow(() -> new NotLoginException("还没有登录无法查询菜单", DEFAULT_MESSAGE, NOT_TOKEN_MESSAGE));

        return (Integer.parseInt(loginIdDefaultNull.toString()));
    }

}
